#!/usr/bin/env python
# -*- coding: utf-8 -*-
#===================================================
# @Time : 2020/06/15 9:06
# @Author : weni09
# @File : EncryptAndDecrypt.py
#===================================================
import hashlib
class MyHashEncryptor:
    @classmethod
    def sha256hex(cls,data):
        sha256 = hashlib.sha256()
        sha256.update(data.encode())
        res = sha256.hexdigest()
        #print("sha256加密结果:", res)
        return res
    @classmethod
    def md5(cls,data):
        return hashlib.md5(data.encode(encoding='UTF-8')).hexdigest()
    @classmethod
    def ifcapitalized(cls,strtype,strobj):
        if strtype.isupper():
            return strobj.upper()
        else:
            return strobj.lower()
    @classmethod
    def myencryped(cls,encryped_type,plaintext):
        if encryped_type.lower() == 'md5' :
            return cls.ifcapitalized(encryped_type,cls.md5(plaintext))
        elif encryped_type.lower() == 'sha256':
            return cls.ifcapitalized(encryped_type,cls.sha256hex(plaintext))
        #print('|'.join([userid, userid_encrypted.upper()]))

